package org.itcast.travel.controller;

import io.jsonwebtoken.Jwts;
import lombok.extern.slf4j.Slf4j;
import org.itcast.travel.config.AliOssConfigProperties;
import org.itcast.travel.pojo.Result;
import org.itcast.travel.utils.AliyunOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * wangcong
 * 2024/12/27 11:32
 */
@RestController
@Slf4j
public class UploadController {
    @Autowired
    private AliOssConfigProperties aliOssConfigProperties;

    @PostMapping("/upload")
    public Result upload(@RequestBody MultipartFile file) throws Exception {
        String filename = file.getOriginalFilename();
        String extName = filename.substring(filename.lastIndexOf("."));
        String url = AliyunOSSUtils.upload(aliOssConfigProperties.getEndpoint(), aliOssConfigProperties.getBucketName(), file.getBytes(), extName);
        return Result.success(url);
    }

}
